Extract actions menu into partial and use it for both Agent Index and Show pages

Glenn 'devalias' Grant 10 years ago
parent
commit
24086308df
3 changed files with 48 additions and 47 deletions
  1. 41 0
      app/views/agents/_action_menu.html.erb
  2. 5 9
      app/views/agents/index.html.erb
  3. 2 38
      app/views/agents/show.html.erb

+ 41 - 0
app/views/agents/_action_menu.html.erb

@@ -0,0 +1,41 @@
1
+<ul class="dropdown-menu" role="menu">
2
+  <% if agent.can_be_scheduled? %>
3
+    <li>
4
+      <%= link_to '<span class="color-success glyphicon glyphicon-refresh"></span> Run'.html_safe, run_agent_path(agent, :return => returnTo), method: :post, :tabindex => "-1" %>
5
+    </li>
6
+  <% end %>
7
+
8
+  <li>
9
+    <%= link_to '<span class="glyphicon glyphicon-eye-open"></span> Show'.html_safe, agent_path(agent) %>
10
+  </li>
11
+
12
+  <li>
13
+    <%= link_to '<span class="glyphicon glyphicon-pencil"></span> Edit'.html_safe, edit_agent_path(agent) %>
14
+  </li>
15
+
16
+  <li class="divider"></li>
17
+
18
+  <li>
19
+    <%= link_to '<span class="glyphicon glyphicon-plus"></span> Clone agent'.html_safe, new_agent_path(id: agent), :tabindex => "-1" %>
20
+  </li>
21
+
22
+  <li>
23
+    <% if agent.disabled? %>
24
+      <%= link_to '<i class="glyphicon glyphicon-play"></i> Enable agent'.html_safe, agent_path(agent, :agent => { :disabled => false }, :return => returnTo), :method => :put %>
25
+    <% else %>
26
+      <%= link_to '<i class="glyphicon glyphicon-pause"></i> Disable agent'.html_safe, agent_path(agent, :agent => { :disabled => true }, :return => returnTo), :method => :put %>
27
+    <% end %>
28
+  </li>
29
+
30
+  <li class="divider"></li>
31
+
32
+  <% if agent.can_create_events? && agent.events.count > 0 %>
33
+    <li>
34
+      <%= link_to '<span class="color-danger glyphicon glyphicon-trash"></span> Delete all events'.html_safe, remove_events_agent_path(agent), method: :delete, data: {confirm: 'Are you sure you want to delete ALL events for this Agent?'}, :tabindex => "-1" %>
35
+    </li>
36
+  <% end %>
37
+
38
+  <li>
39
+    <%= link_to '<span class="color-danger glyphicon glyphicon-remove"></span> Delete agent'.html_safe, agent_path(agent), method: :delete, data: { confirm: 'Are you sure?' }, :tabindex => "-1" %>
40
+  </li>
41
+</ul>

+ 5 - 9
app/views/agents/index.html.erb

@@ -62,15 +62,11 @@
62 62
               </td>
63 63
               <td><%= working(agent) %></td>
64 64
               <td>
65
-                <div class="btn-group btn-group-xs">
66
-                  <%= link_to 'Show', agent_path(agent), class: "btn btn-default" %>
67
-                  <%= link_to 'Edit', edit_agent_path(agent), class: "btn btn-default" %>
68
-                  <%= link_to 'Delete', agent_path(agent), method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-default" %>
69
-                  <% if agent.can_be_scheduled? && !agent.disabled? %>
70
-                    <%= link_to 'Run', run_agent_path(agent, :return => "index"), method: :post, class: "btn btn-default" %>
71
-                  <% else %>
72
-                    <%= link_to 'Run', "#", class: "btn btn-default disabled" %>
73
-                  <% end %>
65
+                <div class="btn-group">
66
+                  <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
67
+                    <span class="glyphicon glyphicon-th-list"></span> Actions <span class="caret"></span>
68
+                  </button>
69
+                  <%= render 'action_menu', :agent => agent, :returnTo => "index" %>
74 70
                 </div>
75 71
               </td>
76 72
             </tr>

+ 2 - 38
app/views/agents/show.html.erb

@@ -21,44 +21,8 @@
21 21
           <% end %>
22 22
 
23 23
           <li class="dropdown">
24
-            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Actions <b class="caret"></b></a>
25
-            <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
26
-              <% if @agent.can_be_scheduled? %>
27
-                <li>
28
-                  <%= link_to '<span class="color-success glyphicon glyphicon-refresh"></span> Run'.html_safe, run_agent_path(@agent, :return => "show"), method: :post, :tabindex => "-1" %>
29
-                </li>
30
-              <% end %>
31
-
32
-              <li>
33
-                <%= link_to '<span class="glyphicon glyphicon-pencil"></span> Edit'.html_safe, edit_agent_path(@agent) %>
34
-              </li>
35
-
36
-              <li class="divider"></li>
37
-
38
-              <li>
39
-                <%= link_to '<span class="glyphicon glyphicon-plus"></span> Clone agent'.html_safe, new_agent_path(id: @agent), :tabindex => "-1" %>
40
-              </li>
41
-
42
-              <li>
43
-                <% if @agent.disabled? %>
44
-                  <%= link_to '<i class="glyphicon glyphicon-play"></i> Enable agent'.html_safe, agent_path(@agent, :agent => { :disabled => false }, :return => "show"), :method => :put %>
45
-                <% else %>
46
-                  <%= link_to '<i class="glyphicon glyphicon-pause"></i> Disable agent'.html_safe, agent_path(@agent, :agent => { :disabled => true }, :return => "show"), :method => :put %>
47
-                <% end %>
48
-              </li>
49
-
50
-              <li class="divider"></li>
51
-
52
-              <% if @agent.can_create_events? && @agent.events.count > 0 %>
53
-                <li>
54
-                  <%= link_to '<span class="color-danger glyphicon glyphicon-trash"></span> Delete all events'.html_safe, remove_events_agent_path(@agent), method: :delete, data: {confirm: 'Are you sure you want to delete ALL events for this Agent?'}, :tabindex => "-1" %>
55
-                </li>
56
-              <% end %>
57
-
58
-              <li>
59
-                <%= link_to '<span class="color-danger glyphicon glyphicon-remove"></span> Delete agent'.html_safe, agent_path(@agent), method: :delete, data: { confirm: 'Are you sure?' }, :tabindex => "-1" %>
60
-              </li>
61
-            </ul>
24
+            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><span class="glyphicon glyphicon-th-list"></span> Actions <span class="caret"></span></a>
25
+            <%= render 'action_menu', :agent => @agent, :returnTo => "show" %>
62 26
           </li>
63 27
         </ul>
64 28
       </div>